package com.atguigu.gmall.order.controller;

import com.atguigu.gmall.common.bean.ResponseVo;
import com.atguigu.gmall.order.service.OrderService;
import com.atguigu.gmall.order.vo.OrderConfirmVo;
import com.atguigu.gmall.oms.vo.OrderSubmitVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OrderController {
    @Autowired
    OrderService orderService;

    @PostMapping("submit")
    @ResponseBody
    public ResponseVo submit(@RequestBody OrderSubmitVO orderSubmitVO){
            orderService.submit(orderSubmitVO);
            return ResponseVo.ok(orderSubmitVO.getOrderToken());
    }



    /**
     * 订单确认页面
     * @return
     */
    @GetMapping("confirm")
    public String confirm(Model model){
       OrderConfirmVo orderConfirmVo =  this.orderService.confirm();
        model.addAttribute("confirmVo",orderConfirmVo);
            return "trade";
    }
}
